<template>
  <component ref="main" :is="view" :user="user" :data="data"></component>
</template>

<script>
import CompMain from './main.vue'
import {get,compNav} from '../public/js/utils.js'
export default {
  data () {
    compNav(this,'nav')
    return {
      currentView:'comp-main',
      data:{},
      common:{},
      history:[{compName:'comp-main'}],
      currentIndex:0,
      user:''
    }
  },
  computed:{
    view(){
      return this.currentView
    }
  },
  components:{
    CompMain
  },
  mounted:async function(){
    this.getUser()
  },
  methods:{
    setData(name,value){
      this.common[name] = value
    },
    getData(name){
      return this.common[name]
    },
    async getUser(){
      if(!this.user){
        const r = await get('/users/getlogininfo');
        if(r && r.err){
          Swal('',r.err,'error')
        }
        if(r.user){
          this.user = r.user
        }
        else{
          this.user = ''
        }
      }
      return this.user
    },
    setUser(user){
      this.user = user
    }
  }

}
</script>
